package com.zkh.myframe.database.mapper;

import java.util.HashMap;
import java.util.Map;

public class SQLMapper {
	//键值对SQL
	private Map<String, SQLEntity> sqlEntityMap;
	
	{
		sqlEntityMap = new HashMap<String, SQLEntity>();
	}

	/**
	 * 获取一个SQLEntity
	 * @param key 唯一键，即XML配置的ID
	 * @return
	 */
	public SQLEntity getSQLEntityOrDefault(String key, SQLEntity defaultValue) {
		return sqlEntityMap.getOrDefault(key, defaultValue);
	}

	/**
	 * 获取一个SQLEntity
	 * @param key 唯一键，即XML配置的ID
	 * @return
	 */
	public SQLEntity getSQLEntity(String key) {
		return sqlEntityMap.get(key);
	}
	
	/**
	 * 设置一个SQLEntity
	 * @param key 唯一键，即XML配置的ID
	 * @param sqlEntity
	 */
	public void setSQLEntity(String key, SQLEntity sqlEntity) {
		if(sqlEntityMap.containsKey(key)) {
			throw new MapperParseException("Mapper中id="+key+"不唯一");
		}
		sqlEntityMap.put(key, sqlEntity);
	}
}
